﻿@model TestOnlineProject.Models.Entities.User
@{
    ViewBag.Title = "Details";
}
@{
    if (!String.IsNullOrEmpty(ViewBag.Msg))
    {
        <script>
            alert("@ViewBag.Msg");
        </script>
    }
}
<script>
    $(document).ready(function() {
        $("#deactivate").click(function() {
            var con = confirm("Are you sure you want to deactivate this user?");
            if (con == true) {
                $.ajax({
                    url: "@Url.Content("~/User/Deactivate")?ids=@Model.UserId" + "-",
                    type: 'GET',
                    success: function(data) {
                        if (data != null) {
                            alert(data);
                            window.location = "@Url.Content("~/User/Details")?id=@Model.UserId";
                        }
                    }
                });
            }
        });

        $("#activate").click(function() {
            var con = confirm("Are you sure you want to activate this user?");
            if (con == true) {
                $.ajax({
                    url: "@Url.Content("~/User/Activate")?ids=@Model.UserId" + "-",
                    type: 'GET',
                    success: function(data) {
                        if (data != null) {
                            alert(data);
                            window.location = "@Url.Content("~/User/Details")?id=@Model.UserId";
                        }
                    }
                });
            }
        });

        $("#delete").click(function() {
            var con = confirm("Are you sure you want to delete this user?");
            if (con == true) {
                $.ajax({
                    url: "@Url.Content("~/User/Delete")?ids=@Model.UserId" + "-",
                    type: 'GET',
                    success: function(data) {
                        if (data != null) {
                            alert(data);
                            window.location = "@Url.Content("~/User/Index")";
                        }
                    }
                });
            }
        });
    });
</script>
<div class="site_map">
    @Html.ActionLink("Home", "Index", "Home", new { Area = "" }, new { }) / @Html.ActionLink("Users", "Index")
    / <span style="word-wrap: break-word">@Model.FullName</span>
</div>
<br />
<div class="main_nav">
    <span>
        <a href="@Url.Content("~/User/Index")">
            <img src="@Url.Content("~/Images/back button.png")"/>
        </a>
    </span>
</div>
<br />
@{
    if (!Model.IsActivated)
    {
        <div class="alert alert-error">
            <span>Deactivated.</span>
        </div>
    }
}
<table class="table table-bordered">
    <tr>
        <td style="width: 150px; text-align: right">
            <span>Username</span>
        </td>
        <td>
            @Html.DisplayFor(model => Model.Username)
        </td>
    </tr>
    <tr>
        <td style="width: 100px; text-align: right">
            <span>E-Mail</span>
        </td>
        <td>
            @Html.DisplayFor(model => Model.Email)
        </td>
    </tr>
    <tr>
        <td style="text-align: right">
            <span>Full Name</span>
        </td>
        <td>
            @Html.DisplayFor(model => Model.FullName)
        </td>
    </tr>
    <tr>
        <td style="text-align: right">
            <span>Profile Picture</span>
        </td>
        <td>
            <div class="fileinput-new thumbnail" style="width: 200px; height: 150px;">
                @if (@Model.ImageUrl == null)
                {
                    <img data-src="holder.js/100%x100%" alt="..." src="~/Images/default_large.png" />
                }
                else
                {
                    <img data-src="holder.js/100%x100%" alt="..." src="~/Images/Profile/@Model.ImageUrl" style="max-width: 200px" />
                }
            </div>
        </td>
    </tr>
    <tr>
        <td style="text-align: right">
            <span>Role</span>
        </td>
        <td>
            @Html.DisplayFor(model => Model.Role.Name)
        </td>
    </tr>
    <tr>
        <td style="text-align: right">
            <span>Profile</span>
        </td>
        <td>
            @Html.ActionLink("Details", "Index", "Account", new { userId = Model.UserId }, new { target = "_blank" })
        </td>
    </tr>
    <tr>
        <td style="text-align: right">
            <span>Joined Time</span>
        </td>
        <td>
            @Html.DisplayFor(model => Model.JoinedTime)
        </td>
    </tr>
    <tr>
        <td style="text-align: right">
            <span>Last Changed Time</span>
        </td>
        <td>
            @Html.DisplayFor(model => Model.LastChangedTime)
        </td>
    </tr>
    <tr>
        <td style="text-align: right">
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id = @Model.UserId })
            @{
                if (Model.RoleId != 1)
                {
                    <span>|</span>
                    if (Model.IsActivated)
                    {
                        <a href="#" id="deactivate">Deactivate</a>
                    }
                    else
                    {
                        <a href="#" id="activate">Activate</a>
                    }
                    <span>|</span>
                    <a href="#" id="delete">Delete</a>
                }
            }
        </td>
    </tr>
</table>